package database;

import java.sql.*;

public class DatabaseOperate {
	private Connection conn = null;
	private Statement stmt = null;
	private ResultSet rtst = null;
	private String url = null;
	
	public boolean connecion(String host,String database,String user,String pwd){
		try{
			Class.forName("com.mysql.jdbc.Driver");
			url = "jdbc:mysql://" + host +"/" + database+"?user=" + user + "&" + "password=" + pwd;
			conn = DriverManager.getConnection(url);
			stmt = conn.createStatement();
			
		}catch(SQLException e){
			e.printStackTrace();
		}catch(ClassNotFoundException e){
			e.printStackTrace();
		}
		return false;
	}
	public ResultSet query(String sql){
		try {
			rtst = stmt.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rtst;
	}

	
	public static void main(String[] args){
		//new ReadData().connection();
		
		DatabaseOperate dtb = new DatabaseOperate();
		dtb.connecion("192.168.1.213", "videose", "root", "ladjzero");
		String sql = "select * from baidu_lr";
		ResultSet rt = dtb.query(sql); 
		try {
			while(rt.next()){
				System.out.print(rt.getString(2));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
